package com.library.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.library.common.base.ApiResult;
import com.library.entity.ResourceEntity;
import com.library.service.ResourceService;
import com.library.service.resourceStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/resourceStatistics")
@Api(tags = "资源统计接口", value = "资源统计接口")
public class resourceStatisticsController {
	@Autowired
	private resourceStatisticsService service;
	@Autowired
	private ResourceService resourceService;

	@ApiOperation(value = "图书排行")
	@GetMapping(value = "/bookRanking")
	public ApiResult bookRanking(Page page, ResourceEntity resource) {
		LambdaQueryWrapper<ResourceEntity> wrapper = Wrappers.lambdaQuery();
		wrapper.like(StrUtil.isNotBlank(resource.getResourceName()), ResourceEntity::getResourceName, resource.getResourceName());
		wrapper.eq(ResourceEntity::getDataTypeId, resource.getDataTypeId());
		wrapper.orderByDesc(ResourceEntity::getPageView);
		return ApiResult.ok(resourceService.page(page,wrapper));
	}

	@ApiOperation(value = "视频排行")
	@GetMapping(value = "/videoRanking")
	public ApiResult videoRanking(Page page, ResourceEntity resource) {
		LambdaQueryWrapper<ResourceEntity> wrapper = Wrappers.lambdaQuery();
		wrapper.like(StrUtil.isNotBlank(resource.getResourceName()), ResourceEntity::getResourceName, resource.getResourceName());
		wrapper.eq(ResourceEntity::getDataTypeId, resource.getDataTypeId());
		wrapper.orderByDesc(ResourceEntity::getPageView);
		return ApiResult.ok(resourceService.page(page,wrapper));
	}

	@ApiOperation(value = "音频排行")
	@GetMapping(value = "/audioRanking")
	public ApiResult audioRanking(Page page, ResourceEntity resource) {
		LambdaQueryWrapper<ResourceEntity> wrapper = Wrappers.lambdaQuery();
		wrapper.like(StrUtil.isNotBlank(resource.getResourceName()), ResourceEntity::getResourceName, resource.getResourceName());
		wrapper.eq(ResourceEntity::getDataTypeId, resource.getDataTypeId());
		wrapper.orderByDesc(ResourceEntity::getPageView);
		return ApiResult.ok(resourceService.page(page,wrapper));
	}

	@ApiOperation(value = "期刊排行")
	@GetMapping(value = "/periodicalRanking")
	public ApiResult periodicalRanking(Page page, ResourceEntity resource) {
		LambdaQueryWrapper<ResourceEntity> wrapper = Wrappers.lambdaQuery();
		wrapper.like(StrUtil.isNotBlank(resource.getResourceName()), ResourceEntity::getResourceName, resource.getResourceName());
		wrapper.eq(ResourceEntity::getDataTypeId, resource.getDataTypeId());
		wrapper.orderByDesc(ResourceEntity::getPageView);
		return ApiResult.ok(resourceService.page(page,wrapper));
	}
}
